import {
  WorkOrderCreateDto,
  WorkOrderDto,
  WorkOrderFindDto,
  WorkOrderListDto,
  WorkOrderProcessDto,
  WorkOrderQueryDto,
  WorkOrderRemoveDto,
  WorkOrderUpdateDto,
} from '@/dtos';
import { WorkOrderService } from '@/services/work-order.service';
import { ok } from '@/utils';
import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  Patch,
  Post,
  Query,
} from '@nestjs/common';
import { BaseController } from './base.controller';
import { CurrentUser } from '@/decorators';

@Controller('work-order')
export class WorkOrderController extends BaseController {
  constructor(private readonly workOrderService: WorkOrderService) {
    super();
  }

  @Post('list')
  async list(@Body() dto: WorkOrderListDto, @CurrentUser('id') id: number) {
    return ok(await this.workOrderService.list(dto, id));
  }

  @Get(':no')
  async getOrderByNo(@Param('no') no: string) {
    return ok(await this.workOrderService.getOrderByNo(no));
  }

  @Post('order')
  async order(@Body() dto: WorkOrderDto, @CurrentUser('id') id: number) {
    return ok(await this.workOrderService.order(dto, id));
  }

  @Post('admin/query')
  async query(@Body() dto: WorkOrderQueryDto) {
    return ok(await this.workOrderService.query(dto));
  }

  @Post('admin/find')
  async find(@Body() dto: WorkOrderFindDto) {
    return ok(await this.workOrderService.findOne(dto.where, dto.select));
  }

  @Post('admin/create')
  async create(@Body() dto: WorkOrderCreateDto) {
    return ok(await this.workOrderService.create(dto.data));
  }

  @Patch('admin/update')
  async update(@Body() dto: WorkOrderUpdateDto) {
    return ok(await this.workOrderService.update(dto));
  }

  @Delete('admin/remove')
  async remove(@Query() dto: WorkOrderRemoveDto) {
    return ok(await this.workOrderService.remove(dto));
  }

  @Post('admin/process')
  async process(@Body() dto: WorkOrderProcessDto) {
    return ok(await this.workOrderService.process(dto));
  }
}
